package com.goods.business.service.imp;

import com.goods.business.mapper.SupplierMapper;
import com.goods.business.pojo.Bizsupplier;
import com.goods.business.service.SupplierService;
import com.goods.common.vo.business.SupplierVO;
import org.apache.ibatis.annotations.Lang;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.util.StringUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
@ComponentScan(value = "com.goods.business.mappper")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    SupplierMapper supplierMapper;

    @Override
    public void delSupplierById(Integer id) {
        supplierMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateSupplierById(Bizsupplier supplierVO, Integer id) {
        Bizsupplier supplierVO1 = supplierVO;
        supplierVO1.setModifiedTime(new Date());
        Integer id1 = id;
        long longValue = id1.longValue();
        supplierVO1.setId(longValue);
        supplierMapper.updateByPrimaryKey(supplierVO1);
    }

    @Override
    public Bizsupplier selectSupplierById(Integer id) {
        return supplierMapper.selectByPrimaryKey(id);

    }

    @Override
    public void supplierAdd(SupplierVO supplierVO) {
        Bizsupplier bizsupplier = new Bizsupplier();
        BeanUtils.copyProperties(supplierVO, bizsupplier);
        bizsupplier.setCreateTime(new Date());
        supplierMapper.insert(bizsupplier);
    }

    @Override
    public List<Bizsupplier> findSupplierList(Integer pageNum, Integer pageSize, String name) {
        if (StringUtil.isEmpty(name)){
            return supplierMapper.selectAll();
        }
        Bizsupplier bizsupplier = new Bizsupplier();
        bizsupplier.setName(name);
        Bizsupplier bizsupplier1 = supplierMapper.selectOne(bizsupplier);
        if (StringUtils.isEmpty(bizsupplier1)){
            return null;
        }
        List<Bizsupplier> bizsuppliers = new ArrayList<Bizsupplier>();
         bizsuppliers.add(bizsupplier1);
        return bizsuppliers;
    }
}
